home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Multimedia / MPC-HC / MPC-HC-x64-Portable.exe / MPC-HC-x64-Portable / Shaders / Sharpen complex.hlsl < prev    next >
Text File  |  2014-10-05  |  3KB  |  92 lines

  1. /*
  2.  * (C) 2003-2006 Gabest
  3.  * (C) 2006-2013 see Authors.txt
  4.  *
  5.  * This file is part of MPC-HC.
  6.  *
  7.  * MPC-HC is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 3 of the License, or
  10.  * (at your option) any later version.
  11.  *
  12.  * MPC-HC is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19.  *
  20.  */
  21.  
  22. sampler s0 : register(s0);
  23. float4 p1 :  register(c1);
  24.  
  25. #define dx (p1[0])
  26. #define dy (p1[1])
  27.  
  28. float4 main(float2 tex : TEXCOORD0) : COLOR
  29. {
  30.     // Pixels definition: original, blurred, corrected, final
  31.     float4 orig;
  32.     float4 blurred;
  33.     float4 corrected;
  34.     float4 final;
  35.  
  36.     // Get neighbor points
  37.     // [ 1,    2, 3 ]
  38.     // [ 4, orig, 5 ]
  39.     // [ 6,    7, 8 ]
  40.  
  41.     orig = tex2D(s0, tex);
  42.     float4 c1 = tex2D(s0, tex + float2(-dx, -dy));
  43.     float4 c2 = tex2D(s0, tex + float2(  0, -dy));
  44.     float4 c3 = tex2D(s0, tex + float2( dx, -dy));
  45.     float4 c4 = tex2D(s0, tex + float2(-dx,   0));
  46.     float4 c5 = tex2D(s0, tex + float2( dx,   0));
  47.     float4 c6 = tex2D(s0, tex + float2(-dx,  dy));
  48.     float4 c7 = tex2D(s0, tex + float2(  0,  dy));
  49.     float4 c8 = tex2D(s0, tex + float2( dx,  dy));
  50.  
  51.     // Computation of the blurred image (gaussian filter)
  52.     // to normalize the values, we need to divide by the coeff sum
  53.     // 1/(1+2+1+2+4+2+1+2+1) = 1/16 = 0.0625
  54.     blurred = (c1 + c3 + c6 + c8 + 2 * (c2 + c4 + c5 + c7) + 4 * orig) * 0.0625;
  55.  
  56.     // substract blurred image from original image
  57.     corrected = 2 * orig - blurred;
  58.  
  59.     // edge detection
  60.     float delta1;
  61.     float delta2;
  62.     float value;
  63.  
  64.     // using Sobel filter
  65.     // horizontal gradient
  66.     // [ -1, 0, 1 ]
  67.     // [ -2, 0, 2 ]
  68.     // [ -1, 0, 1 ]
  69.     delta1 = (c3 + 2 * c5 + c8) - (c1 + 2 * c4 + c6);
  70.  
  71.     // vertical gradient
  72.     // [ -1, -2, -1 ]
  73.     // [  0,  0,  0 ]
  74.     // [  1,  2,  1 ]
  75.     delta2 = (c6 + 2 * c7 + c8) - (c1 + 2 * c2 + c3);
  76.  
  77.     // computation
  78.     value = sqrt(mul(delta1, delta1) + mul(delta2, delta2));
  79.  
  80.     if (value > 0.3) {
  81.         // if we have an edge, use sharpen
  82.         #define Sharpen_val0 2.0
  83.         #define Sharpen_val1 0.125
  84.         final = orig * 2 - (c1 + c2 + c3 + c4 + c5 + c6 + c7 + c8) * 0.125;
  85.         //final = float4(1, 0, 0, 0);
  86.         return final;
  87.     }
  88.  
  89.     // else return corrected image
  90.     return corrected;
  91. }
  92.